package meijuli.com.join51.business.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

/**
 * 分类
 *
 * @author jack 2017-04-25 10:16
 */
public class Category implements Parcelable {

    public static final int STATUS_OPEN = 1;
    public static final int STATUS_CLOSE = 0;
    private String parentId; //扩展字段
    private String dmId;
    private String categoryName;
    private int sort; //排序
    private int status;

    public Category() {

    }

    protected Category(Parcel in) {
        parentId = in.readString();
        dmId = in.readString();
        categoryName = in.readString();
        sort = in.readInt();
        status = in.readInt();
    }

    public static final Creator<Category> CREATOR = new Creator<Category>() {
        @Override
        public Category createFromParcel(Parcel in) {
            return new Category(in);
        }

        @Override
        public Category[] newArray(int size) {
            return new Category[size];
        }
    };

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    public String getDmId() {
        return dmId;
    }

    public void setDmId(String id) {
        this.dmId = id;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(parentId);
        parcel.writeString(dmId);
        parcel.writeString(categoryName);
        parcel.writeInt(sort);
        parcel.writeInt(status);
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Category) {
            Category other = (Category) obj;
            // 防止dmId为空
            if (TextUtils.isEmpty(dmId)) {
                return TextUtils.isEmpty(other.getDmId());
            }
            return dmId.equals(other.getDmId());
        }
        return false;
    }
}
